package versionControl.aspectj.library;

import java.io.PrintStream;

/*
 * Expose an abstract showHistory(Versioned) pointcut that 
 * prints all the versions before and after the pointcut
 */
public abstract aspect History{
	public abstract pointcut showHistory(Versioned Obj);
	
	protected PrintStream out = System.out;
	
	before(Versioned obj): showHistory(obj) && (!within(versionControl.aspectj.library.*)) {
		printHistory(obj, out);
	}
	
	after(Versioned obj): showHistory(obj) && (!within(versionControl.aspectj.library.*)) {
		printHistory(obj, out);
	}
	
	private void printHistory(Versioned obj, PrintStream out){
		out.println("archived versions:");
		for (Versioned version : obj.getVersions().values()){
			out.println("obj : " + version.toString());
		}
	}		
}